﻿<%@ Control Language="C#" AutoEventWireup="true" CodeBehind="LXGL.ascx.cs" Inherits="CDCW.Web.View.UCMangForm.LXGL" %>
<div class="row">
    <div class="col-xs-12">
        <div class="form-group">
            <label>创新成果类型名称</label>
            <asp:TextBox ID="txtName" runat="server" CssClass="form-control w5 validate[required]"></asp:TextBox>
        </div>
        <div class="form-group">
            <label>所属分类</label>
            <asp:DropDownList ID="ddlTopID" runat="server" CssClass="form-control w5 validate[required] ddlTopID"></asp:DropDownList>
        </div>


        <table class="table table-bordered table-striped table-hover rulediv">
            <thead>
                <tr>
                    <%--<th style="width:60px">序号</th>--%>
                    <th>规则</th>
                    <th style="width:80px">分值</th>
                    <th style="width:80px"></th>
                </tr>
            </thead>
            <tbody class="ruletb">

            </tbody>
            <tfoot>
                <tr>
                    <%--<th></th>--%>

                    <td>
                        <input type="text" name="name"  class="form-control name"  placeholder="此处输入评分规则" /></td>
                    <td>
                        <input type="text" name="score"  class="form-control score"  placeholder="分值"  /></td>
                    <td style="vertical-align: middle;"><a style="color: dodgerblue; cursor: pointer" onclick="add()">新增</a></td>
                </tr>
            </tfoot>
        </table>

        <%--<div class="form-group txtFLDesp">
            <label>备注</label>
            <asp:TextBox ID="txtRemark" runat="server"  CssClass="form-control" TextMode="MultiLine"></asp:TextBox>
        </div>--%>
        <%--<div class="form-group rulediv">
            <div class="row">
                <label class="col-xs-8">规则</label>
                <label class="col-xs-2">分值</label>
                <label class="col-xs-2"><a class="btn btn-default" onclick="add()">新   增</a></label>
            </div>
        </div>--%>
    </div>
    <div class="col-xs-4">
        <input type="hidden" runat="server" class="json" id="json" />
    </div>
</div>
<%--<style>
    .rule {
        margin-bottom: 10px;
    }
</style>--%>
<script>
    if ($(".json").val()) {
        $(".rule").remove();
        var obj = JSON.parse($(".json").val());
        $(obj).each(function (i, m) {
            add(m);
        })
    }
    $(".ddlTopID").change(function () {
        if ($(this).val() != "0") {
            $(".rulediv").removeClass("hide")
        } else {
            $(".rulediv").addClass('hide')
        }
    })
    $(".ddlTopID").trigger("change");

    function add(obj) {
        //var html = '<div class="row rule">'
        //         + '     <div class="col-xs-8 ">'
        //         + '         <input type="text" class="form-control validate[required]" value="' + (obj ? obj.rule : '') + '" />'
        //         + '     </div>'
        //         + '     <div class="col-xs-2 ">'
        //         + '         <input type="text" class="form-control validate[required]" value="' + (obj ? obj.score : '') + '" />'
        //         + '     </div>'
        //         + '     <div  class="col-xs-2"><a class="btn btn-danger" onclick="del(this)">删除</a></div>'
        //         + '</div>';
        //$(html).appendTo($(".rulediv"));

        if (!obj) {
            if ($(".name").val() && $(".score").val()) {
                obj = { 'rule': '', 'score': '' };
                obj.rule = $(".name").val();
                obj.score = $(".score").val();
                $(".name").val('');
                $(".score").val('');
            }
            else {
                parent.MyDialog.warning('请输入规则和分数');
                return;
            }
        }

        var html = '<tr class="rule">'
                 //+ '    <th>1</th>'
                 + '    <td><span>' + (obj ? obj.rule : '') + '</span></td>'
                 + '    <td><span>' + (obj ? obj.score : '') + '</span></td>'
                 + '    <td><a style="color: red; cursor: pointer" onclick="del(this)">删除</a></td>'
                 + '</tr>';
        $(html).appendTo($(".ruletb"));
    }
    function del(obj) {
        $(obj).parent().parent().remove();
    }

    function getdata() {
        var obj = [];
        $(".rule").each(function () {
            var model = { "rule": "", "score": "" };
            //model.rule = $($(this).find("input")[0]).val();
            //model.score = $($(this).find("input")[1]).val();
            model.rule = $($(this).find("span")[0]).text();
            model.score = $($(this).find("span")[1]).text();
            obj.push(model);
        })
        $(".json").val(JSON.stringify(obj));
    }
    //@ sourceURL=LXGL.js;
</script>
